package com.dhh.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.dhh.R;
import com.dhh.dao.DataBaseHelper;
import com.dhh.util.manager.FoodManager;
import com.dhh.vo.Food;

import greendroid.app.GDActivity;

public class ShowFoodDetail  extends GDActivity{
	private DataBaseHelper db;
	private FoodManager fManager;
	private TextView foodName;
	private TextView foodGroup;
	private TextView carb;
	private TextView protein;
	private TextView fat;
	private TextView energy;
	private Food food;
	
	@Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setActionBarContentView(R.layout.show_food_detail);   
        db = new DataBaseHelper(getBaseContext());
        db.openDataBase();        
        fManager = new FoodManager(db);
		food = new Food();
        initActionBar();
	}
	
	@Override
	public void onStart(){
		super.onStart();		
        initView();
        fillData();
	}
	
	@Override
    public void onResume(){
    	super.onResume();
        db.openDataBase();       
    }
    
    @Override
	protected void onPause(){
		super.onPause();
		if (db != null) {
			db.close();
		}
	}
    
    @Override
	protected void onStop(){
		super.onStop();
	}
    
	private void initActionBar(){
		getActionBar().setTitle("Food Detail");
        getActionBar().setBackgroundColor(Color.rgb(14, 166, 249));
        getActionBar().getChildAt(0).
        	setOnClickListener(new OnClickListener(){
				@Override
				public void onClick(View v) {
					Intent intent = new Intent(ShowFoodDetail.this,HomeActivity.class);	
					startActivity(intent);
				}}); 
	}
	
	public void initView(){
		foodName = (TextView) this.findViewById(R.id.ac_food_name);
		foodGroup = (TextView) this.findViewById(R.id.ac_food_group);
		fat = (TextView) this.findViewById(R.id.ac_fat);
		protein = (TextView) this.findViewById(R.id.ac_protein);
		carb = (TextView) this.findViewById(R.id.ac_carb);
		energy = (TextView) this.findViewById(R.id.ac_calorie);
	}
	
	private void fillData(){
		food = fManager.getFood(getIntent().getStringExtra("foodId"));
		foodName.setText(food.getFoodName()!=null?food.getFoodName():"");
		foodGroup.setText(food.getFoodGroup()!=null?food.getFoodGroup():"");
		fat.setText(food.getFat()!=null?food.getFat():"");
		protein.setText(food.getProtein()!=null?food.getProtein():"");
		carb.setText(food.getCarb()!=null?food.getCarb():"");
		energy.setText(food.getEnergy());
	}
}
